package com.ds.lens.collector.receive.handler;

import com.ds.lens.collector.receive.constants.HandlerType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ethan
 * @author WeiShaoying
 */
@Component
public class HandlerFactory {


    @Autowired
    private MetricsHandler metricsHandler;

    @Autowired
    private EventsHandler eventsHandler;

    @Autowired
    private AlertHandler alertHandler;


    private Map<String, Handler> handlerMapFactory = new HashMap<>();

    public Handler getHandler(String type) {
        return handlerMapFactory.get(type);
    }

    @PostConstruct
    private void setHandlerMap() {
        handlerMapFactory.put(HandlerType.metrics.toString(), metricsHandler);
        handlerMapFactory.put(HandlerType.devops_event.toString(), eventsHandler);
        handlerMapFactory.put(HandlerType.alert.toString(), alertHandler);
    }
}
